﻿using System.Collections.Generic;
using System.Linq;

namespace Pap.Data
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Role : IRole
    {
        #region IRole Members

        /// <summary>
        /// Gets the permissions.
        /// </summary>
        IEnumerable<IPermission> IRole.Permissions
        {
            get
            {
                return this.RolesPermissions.Select(t => t.Permission).OfType<IPermission>();
            }
        }

        /// <summary>
        /// Gets the users.
        /// </summary>
        IEnumerable<IUser> IRole.Users
        {
            get
            {
                return this.UsersRoles.Select(t => t.User).OfType<IUser>();
            }
        }

        /// <summary>
        /// Gets the role permissions.
        /// </summary>
        public IEnumerable<IRolesPermission> RolePermissions
        {
            get { return this.RolesPermissions.OfType<IRolesPermission>(); }
        }

        /// <summary>
        /// Adds the permission.
        /// </summary>
        /// <param name="perm">The perm.</param>
        void IRole.AddPermission(IPermission perm)
        {
            this.RolesPermissions.Add(new RolesPermission() { PermissionID = perm.PermissionID });
        }

        /// <summary>
        /// Deletes all permissions.
        /// </summary>
        void IRole.DeleteAllPermissions()
        {

        }

        #endregion
    }
}
